using System;
using System.Runtime.Serialization;
using System.Text;

namespace zevenseas.Community.Web.UI.WebControls.WebParts
{
    public class zsWebPartException : ApplicationException
    {
        #region Properties

        private string whatHasBeenAffected;
        private string whatActionsCanUserTake;
        private string supportInformation;

        public string WhatHasBeenAffected
        {
            get { return whatHasBeenAffected; }
            set { whatHasBeenAffected = value; }
        }

        public string WhatActionsCanUserTake
        {
            get { return whatActionsCanUserTake; }
            set { whatActionsCanUserTake = value; }
        }

        public string SupportInformation
        {
            get { return supportInformation; }
            set { supportInformation = value; }
        }

        #endregion

        #region Constructors

        public zsWebPartException(string Message)
            : base(Message)
        {
        }

        public zsWebPartException(string Message, Exception Inner)
            : base(Message, Inner)
        {
        }

        public zsWebPartException(string Message, Exception Inner, string WhatHasBeenAffected, string WhatActionsCanUserDo, string SupportInformation)
            : base(Message, Inner)
        {
            whatHasBeenAffected = WhatHasBeenAffected;
            whatActionsCanUserTake = WhatActionsCanUserDo;
            supportInformation = SupportInformation;
        }

        protected zsWebPartException(SerializationInfo Info, StreamingContext Context)
            : base(Info, Context)
        {
            whatHasBeenAffected = Info.GetString("whatHasBeenAffected");
            whatActionsCanUserTake = Info.GetString("whatActionsCanUserDo");
            supportInformation = Info.GetString("supportInformation");
        }

        #endregion

        #region Methods

        public override void GetObjectData(SerializationInfo Info, StreamingContext Context)
        {
            Info.AddValue("whatHasBeenAffected",
                          whatHasBeenAffected, typeof(String));
            Info.AddValue("whatActionsCanUserDo",
                          whatActionsCanUserTake, typeof(String));
            Info.AddValue("supportInformation",
                          supportInformation, typeof(String));
            base.GetObjectData(Info, Context);
        }

        public string GetErrorMessage(bool DebugMode)
        {
            StringBuilder errorMessage = new StringBuilder();
            errorMessage.AppendLine("<b>What has happened?</b><br>");
            errorMessage.AppendLine(Message);
            errorMessage.AppendLine("<br>");

            if (!string.IsNullOrEmpty(whatHasBeenAffected))
            {
                errorMessage.AppendLine("<b>What has been affected?</b><br>");
                errorMessage.AppendLine(whatHasBeenAffected);
                errorMessage.AppendLine("<br>");
            }
            if (!string.IsNullOrEmpty(whatActionsCanUserTake))
            {
                errorMessage.AppendLine("<b>What actions can be taken?</b><br>");
                errorMessage.AppendLine(whatActionsCanUserTake);
                errorMessage.AppendLine("<br>");
            }

            if (!DebugMode)
            {
                errorMessage.AppendLine("<!--");
            }
            errorMessage.AppendLine("<br><b>Web Part Running in Debug Mode</b><br>");
            errorMessage.AppendLine("<b>SUPPORT INFORMATION:<br>");
            if (!string.IsNullOrEmpty(supportInformation))
            {
                errorMessage.AppendLine(supportInformation);
            }
            errorMessage.Append("<br>");
            errorMessage.AppendLine("<b>ORIGINAL EXCEPTION</b><br>");
            if (InnerException != null) errorMessage.AppendLine(InnerException.ToString());

            if (!DebugMode)
            {
                errorMessage.AppendLine("-->");
            }

            return errorMessage.ToString();
        }

        #endregion
    }
    
}